<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <!-- 图标轮播 -->
      <swiper-slide v-for="(page, index) in pages" :key="index">
        <div
          class="icon"
          v-for="(icon, index) in page"
          :key="icon.id"
          v-if="index < 8"
        >
          <div class="icon-img">
            <img
              class="icon-img-content"
              :src="icon.imgUrl"
              :alt="icon.imgUrl"
            />
          </div>
          <p class="icon-desc">{{ icon.desc }}</p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: "Icons",
  props:{
    iconsList:{
      type:Array
    }
  },
  data() {
    return {
      //   轮播组件配置项
      swiperOption: {},
    };
  },
  computed: {
    //   对图标列表分页，每页显示8个图标
    pages() {
      const pages = []; // 保存分页结果
      this.iconsList.forEach((item, index) => {
        const page = Math.floor(index / 8); // 页数
        if (!pages[page]) {
          //  当前页数不存在
          pages[page] = [];
        }
        pages[page].push(item); // 保存分页结果
      });
      return pages;
    }
  }

};
</script>

<style lang="less" scoped>
@import url("~@/assets/styles/varibles.less");
@import url("~@/assets/styles/mixins.less");

.icons {
  .swiper-container {
    height: 0;
     margin-top: .1rem;
    padding-bottom: 50%;
  }
  .icon {
    position: relative;
    float: left;
    width: 25%;
    height: 0;
    padding-bottom: 25%;
    &-img {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0.44rem;
      box-sizing: border-box;
      padding: 0.1rem;
      &-content {
        display: block;
        height: 100%;
        margin: 0 auto;
      }
    }
    &-desc {
      position: absolute;
      left: 0;
      right: 0;
      bottom: 0;
      height: 0.44rem;
      padding: 0 .3rem;
      line-height: 0.44rem;
      text-align: center;
      color: @iconFontColor;
      .text-hidden()
    }
  }
}
</style>
